package com.qingchunlin.blogsystem.config;

import com.qingchunlin.blogsystem.common.enums.BusinessStatus;
import com.qingchunlin.blogsystem.entity.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ResponseBody
@ControllerAdvice
public class ErrorAdvice {

    @ExceptionHandler
    public Result<String> errorHandler(Exception e) {
        log.error("发生异常: e{}", e.getMessage());
        Result<String> result = new Result<>();
        result.setBusinessStatus(BusinessStatus.FAILURE);
        result.setErrorMessage("系统内部错误");
        result.setData("");
        return result;
    }
}
